#include <stdio.h>
#include <math.h>
#include <stdlib.h>

double power(double x,int n);  /*函数定义*/

int main()
{
    double x,result;  /*定义变量*/
    int n;
    printf("Please input x,n:",x,n);
    scanf("%lf %d",&x,&n);
    if(n<0)   /*控制条件*/
    {
        printf("Assertion failed: n >= 0,file main.c,line 13");  /*输出错误信息*/
        exit(0);  /*强制跳出程序不再执行*/
    }
    result=power(x,n);   /*递归函数*/
    printf("%.2f to the power of %d is %.4f",x,n,result);
    return 0;
}

double power(double x,int n)
{
    if(n==0)    /*不同情况下开始递归*/
    {
        return 1;
    }
    if(n==1)
    {
        return x;
    }
    if(n>=2&&n%2==0)
    {
        return power(pow(x,2),n/2);
    }
    if(n>=2&&n%2!=0)
    {
        return x*power(x,n-1);
    }
}